import 'package:bxultimate/app/router/router_name.dart';
import 'package:bxultimate/app/theme/app_theme.dart';
import 'package:bxultimate/app/theme/gaps.dart';
import 'package:bxultimate/domain/home/home_data_dto.dart';
import 'package:bxultimate/resources/assets.dart';
import 'package:bxultimate/widgets/mk_load_image.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

class AppTaskCard extends StatefulWidget {

  final Task task;

  const AppTaskCard({super.key, required this.task});

  @override
  State<AppTaskCard> createState() => _AppTaskCardState();
}

class _AppTaskCardState extends State<AppTaskCard> {
  @override
  Widget build(BuildContext context) {
    var itemWidth = Get.width * 0.7;
    return GestureDetector(
      onTap: () {
        Get.toNamed(RouterName.taskDetail, arguments: widget.task.id);
      },
      child: Container(
        margin: EdgeInsets.only(right: 12),
        width: itemWidth,
        decoration: BoxDecoration(
            borderRadius: AppTheme.iBorderRadius),
        clipBehavior: Clip.antiAlias,
        height: 120,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              width: itemWidth,
              height: 60,
              decoration: BoxDecoration(color: Color(0xFFFFBB95)),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Padding(
                        padding: EdgeInsets.only(left: AppTheme.iDefaultPadding,top: 8),
                        child: Text(
                          '${widget.task.taskTypeStr}',
                          style: TextStyle(
                              color: Colors.white,
                              fontSize: 16,
                              fontWeight: FontWeight.bold),
                        ),
                      ),
                      TDTag(
                        '${widget.task.isAcceptStr}',
                        size: TDTagSize.small,
                        theme: TDTagTheme.danger,
                      ),
                    ],
                  ),
                  Expanded(
                      child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      LoadAssetImage(
                        Assets.homeLocation,
                        width: 40,
                      ),
                      Padding(
                        padding: EdgeInsets.only(right: AppTheme.iDefaultPadding),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.end,
                          children: [
                            Text.rich(TextSpan(
                                text: '距您',
                                style: TextStyle(color: Colors.white),
                                children: [
                                  TextSpan(
                                      text: '${widget.task.distance}米',
                                      style: TextStyle(
                                          color: Colors.white,
                                          fontWeight: FontWeight.bold,
                                          fontSize: 16)),
                                ])),
                            // Text(
                            //   '${widget.task.address}',
                            //   overflow: TextOverflow.ellipsis,
                            //   style: TextStyle(color: Colors.white, fontSize: 12),
                            // ),
                          ],
                        ),
                      )
                    ],
                  ))
                ],
              ),
            ),
            Expanded(
                child: Container(
              width: itemWidth,
              padding: EdgeInsets.only(left: AppTheme.iDefaultPadding),
              decoration: BoxDecoration(color: Colors.white),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    '${widget.task.title}',
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
                  ),
                  Gaps.vGap8,
                  Text(
                    '${widget.task.info}',
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(fontSize: 12),
                  )
                ],
              ),
            ))
          ],
        ),
      ),
    );
  }
}
